package com.identify.identifydrawings;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

public class CutImageAdapter extends RecyclerView.Adapter<CutImageAdapter.ViewHolder> {

    private List<String> mImageList;
    private OnItemClickLitener   mOnItemClickLitener;



    static class ViewHolder extends RecyclerView.ViewHolder {
        ImageView cutimage;
        TextView recognition;
        public ViewHolder(View view) {
            super(view);
            cutimage = (ImageView) view.findViewById(R.id.cut_image);
            recognition = (TextView) view.findViewById(R.id.recognition);
        }

    }

    public CutImageAdapter(List<String> imageList) {
        mImageList = imageList;
        Log.e("TAG", "mImageList=" + mImageList);
    }
    //设置回调接口
    public interface OnItemClickLitener{
        void onItemClick(View view, int position);
    }
    public void setOnItemClickLitener(OnItemClickLitener mOnItemClickLitener){
        this.mOnItemClickLitener = mOnItemClickLitener;
    }
    @Override

    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_cutimage, null, false);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder,final int position) {
        String imgePath = mImageList.get(position);
        Bitmap bmp = BitmapFactory.decodeFile(imgePath);
        holder.cutimage.setImageBitmap(bmp);
        //设为识别内容
        //holder.fruitName.setText(fruit.getName());
        //通过为条目设置点击事件触发回调
        if (mOnItemClickLitener != null) {
            holder.cutimage.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    mOnItemClickLitener.onItemClick(view, position);
                }
            });
        }
    }


    @Override
    public int getItemCount() {
        return mImageList.size();
    }
}